package com.hxh.component.business.utils;

import com.alibaba.fastjson.JSON;
import com.hxh.component.basicore.Base.app.AppManager;
import com.hxh.component.basicore.util.Utils;
import com.hxh.component.business.R;
import com.hxh.component.pickerview.ui.picker.common.PickerShowType;
import com.hxh.component.ui.alertview.AlertView;

import java.util.ArrayList;

import cn.qqtheme.framework.entity.City;
import cn.qqtheme.framework.entity.County;
import cn.qqtheme.framework.entity.Province;
import cn.qqtheme.framework.picker.AddressPicker;
import cn.qqtheme.framework.picker.OptionPicker;
import cn.qqtheme.framework.picker.WheelPicker;

/**
 * author mardawang
 * <p>
 * email:wy363681759@163.com
 * <p>
 * date: 21/11/2018
 * <p>
 * desc:
 */

public class PickerUtils {
    public static OptionPicker showDefaulStyleSingleSelectPicker(String[] datas, OptionPicker.OnOptionPickListener listener) {
        OptionPicker picker = new OptionPicker(AppManager.getCurrentActivity(), datas);
        picker.setSelectedIndex(0);
        picker.setTextSize(22);
        picker = setDefaultStyle(picker);
        picker.setOnOptionPickListener(listener);
        return picker;
    }

    public static OptionPicker showDefaulStyleSingleSelectPicker(String title, String[] datas, OptionPicker.OnOptionPickListener listener) {
        OptionPicker picker = new OptionPicker(AppManager.getCurrentActivity(), datas);
        picker.setSelectedIndex(0);
        picker.setTextSize(22);
        picker = setDefaultStyle(picker);
        picker.setOnOptionPickListener(listener);

        return picker;
    }

    //自定义 地址 pickerview
    public static AddressPicker showDefaulStyleAddressPicker(AddressPicker.OnAddressPickListener lis) {
        ArrayList<Province> data = new ArrayList<Province>();
        String json = Utils.SP.getString(Constant.CITY_JSON);

        data.addAll(JSON.parseArray(json, Province.class));
        AddressPicker picker = new AddressPicker(AppManager.getCurrentActivity(), data);
        picker.setHideProvince(false);
        picker.setHideCounty(false);
        picker = setDefaultStyle(picker);
        picker.setOnAddressPickListener(lis);
        return picker;
    }
    //自定义 地址 pickerview
    public static AddressPicker showNoForeignPicker(AddressPicker.OnAddressPickListener lis) {
        ArrayList<Province> data = new ArrayList<Province>();
        String json = Utils.SP.getString(Constant.CITY_NO_FOREIGN_JSON);
        if (null == json){
            return null;
        }
        data.addAll(JSON.parseArray(json, Province.class));
        AddressPicker picker = new AddressPicker(AppManager.getCurrentActivity(), data);
        picker.setHideProvince(false);
        picker.setHideCounty(false);
        picker = setDefaultStyle(picker);
        picker.setOnAddressPickListener(lis);
        return picker;
    }

    //自定义 地址 pickerview  禁止外部点击
    public static AddressPicker showNoBackStyleAddressPicker(AddressPicker.OnAddressPickListener lis) {
        ArrayList<Province> data = new ArrayList<Province>();
        String json = Utils.SP.getString(Constant.CITY_JSON);

        data.addAll(JSON.parseArray(json, Province.class));
        AddressPicker picker = new AddressPicker(AppManager.getCurrentActivity(), data);
        picker.setHideProvince(false);
        picker.setHideCounty(false);
        picker.setCancelable(false);
        picker = setDefaultStyle(picker);

        picker.setOnAddressPickListener(lis);
        return picker;
    }

    public static AlertView showCustomStyleDialog(AlertView.Builder builder)
    {
        return new AlertView(builder);
    }

    private static <T extends WheelPicker> T setDefaultStyle(T picker) {
        picker.setTextSize(18);

        picker.setSubmitTextColor(Utils.Resource.getColor(R.color.default_blue));
        picker.setTopLineColor(Utils.Resource.getColor(R.color.line_e5e5e5));
        picker.setCancelTextColor(Utils.Resource.getColor(R.color.grav_6));
        picker.setDividerColor(Utils.Resource.getColor(R.color.line_e5e5e5));

        picker.setPressedTextColor(Utils.Resource.getColor(R.color.black));
        return picker;
    }
}
